package com.ecable.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Vector;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ecable.exception.ConnectionException;
import com.ecable.exception.DataNotFoundException;
import com.ecable.bean.StateTO;
import com.ecable.delegate.StateMgrDelegate;
import com.ecable.util.UtilConstants;

public class StateUpdation extends HttpServlet {

	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		
		
		RequestDispatcher rd=null;

		StateTO vsto=null;
		String path="";
		
		try{
			
			int sid=Integer.parseInt(request.getParameter("sid"));
			
			StateMgrDelegate smd=new StateMgrDelegate();
			
			try{
			
			 vsto=smd.viewStateInfo(sid);
			}
			
			catch (DataNotFoundException le) {
				request.setAttribute("status", UtilConstants._ALL_STATES_FAILED);
				rd=request.getRequestDispatcher(UtilConstants._LOGIN_FAILED_PAGE);
			}
			
			
			
			if(vsto!=null){
				
				request.setAttribute("StatesInfo", vsto);
				request.setAttribute("status", UtilConstants._ALL_STATES);
				
				path=UtilConstants._UPDATE_STATE_HOME;
				
				}
			else{
				
				request.setAttribute("status", UtilConstants._ALL_STATES_FAILED);
				
				path=UtilConstants._UPDATE_STATE_HOME;
				
			}
		}
		catch (NullPointerException e) {
			
			e.printStackTrace();
			
			request.setAttribute("status", UtilConstants._INVALIED_ENTRY);
			
			path=UtilConstants._UPDATE_STATE_HOME;
			
		}
		
		rd=request.getRequestDispatcher(path);
		rd.forward(request, response);
		
		
		
		
		
		
		
		
		
		
		
		
	}

}
